<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            border: 3px dashed #ccc;
            padding: 20px;
        }
    </style>
    <script src="../assets/js/vue.js"></script>
</head>
<body>
    <div id="app" class="box">
        <p>父组件</p>
        <comp-a @update:msg=" setMsg "></comp-a>
        <br>
        <comp-b :msg="temp"></comp-b>
    </div>

    <script type="text/x-template" id="CompA">
        <div class="box">
            <p>子组件A</p>
            <p>msg : {{ msg }}</p>
            <input type="button" value="发送msg数据" @click=" $emit('update:msg',msg) ">
        </div>
    </script>

    <script type="text/x-template" id="CompB">
        <div class="box">
            <p>子组件B</p>
            <p>msg:{{ msg }}</p>
        </div>
    </script>

    <script>
        Vue.component("CompA",{
            template:"#CompA",
            data() {
                return {
                    msg:"CompA-的数据"
                }
            },
        })

        Vue.component("CompB",{
            template:"#CompB",
            props:["msg"]
        })

        new Vue({
            el:"#app",
            data:{
                temp:""
            },
            methods: {
                setMsg(nv){
                    this.temp = nv;
                }
            },
        })
    </script>
</body>
</html>